package com.example.lib_base.view

import android.os.Bundle
import android.os.PersistableBundle
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding

abstract class BaseActivity <VDB : ViewDataBinding> :AppCompatActivity(){
    protected lateinit var mDataBinding: VDB

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        mDataBinding = DataBindingUtil.setContentView(this,getLayoutID())

        initViews()
    }

    override fun onSaveInstanceState(outState: Bundle, outPersistentState: PersistableBundle) {
        super.onSaveInstanceState(outState, outPersistentState)
        saveActivityState(outState)
    }

    override fun onRestoreInstanceState(
        savedInstanceState: Bundle?,
        persistentState: PersistableBundle?
    ) {
        super.onRestoreInstanceState(savedInstanceState, persistentState)
        savedInstanceState?.run {
            getActivityState(this)
        }
    }

    protected open fun getActivityState(state: Bundle){

    }

    protected open fun saveActivityState(state:Bundle){

    }

    protected open fun initViews(){

    }

    abstract fun getLayoutID():Int
}